
//liuweibo add start 20120326
package com.android.matmanual;



import android.app.Activity;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.Vibrator;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;



public class VibratorTest extends BaseActivity 
{
	TextView mVibratorState;
	Vibrator mVibrator; 
	boolean mVibratorStateOpenFlag =false; 
	WakeLock mWakeLock;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
     
		setContentView(R.layout.vibrator_test);
		setTitle(R.string.vibrator_title);
		   PowerManager pm =
		           (PowerManager) getSystemService(POWER_SERVICE); 
		    mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, 
		          "XYTEST"); 
		    mWakeLock.acquire(); 		
		mVibratorState = (TextView) findViewById(R.id.vibrator_state);	

		mVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);  
		
		long[] pattern = {300, 800, 300, 800}; // OFF/ON/OFF/ON...    
		mVibrator.vibrate(pattern, 2);
		
	
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		int result = TestControl.GetKeyEvent(keyCode);
		if (result != TestControl.DO_NOTHING) {
			setResult(result);
			finish();
	    }
	    return true;
	}
	@Override    
	protected void onStop() {    

		finish();
		super.onStop();    
	}   
    @Override
    protected void onDestroy() {
    	// TODO Auto-generated method stub
		if(mWakeLock!=null)
		{
			mWakeLock.release(); 
			mWakeLock = null;
		}
		if(null!=mVibrator){    
			mVibrator.cancel();    
		}    
    	super.onDestroy();
    }	
	@Override
	public void onAttachedToWindow() 
	{
		// TODO Auto-generated method stub
		super.onAttachedToWindow();
		this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
	}

}
//liuweibo end
		 